<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ taglib prefix="limits" uri="/WEB-INF/tld/limits.tld"%>
<%@ page import="com.hzqy.commons.utils.ConstantUtils" %>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>内容管理</title>
	<link rel="stylesheet" type="text/css"	href="../static/js/themes/defalut.css">
	<link rel="stylesheet" type="text/css"	href="../static/js/themes/public.css">
	<link rel="stylesheet" type="text/css"	href="../static/js/themes/ddspstyle.css">
	<link rel="stylesheet" type="text/css"	href="../static/js/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css"	href="../static/js/themes/icon.css">
	<link href="../static/css/uploadify.css" rel="stylesheet" type="text/css"/>


	<script type="text/javascript" src="../static/js/jquery.min.js"></script>
	<script type="text/javascript" src="../static/js/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../static/js/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript" src="../static/js/index.js"></script>
	<script src="../static/js/jquery.uploadify.js" type="text/javascript"></script>
	<%
		String para =request.getParameter("f_cc_programatype");
		int f_cc_programatype = 1;
		if(para != null)
			f_cc_programatype = Integer.valueOf(para);
		String []nonceObj=ConstantUtils.getNonceObject();
	%>


	<script type="text/javascript">
		var queryParams;
		var f_cc_programatype = <%=f_cc_programatype%>;
		function EasyuiDatagrid() {
			if(f_cc_programatype == 7){
				$("#more_condition").show();
				$("#more_condition_one").show();
			}
			$("#easyui-datagrid").datagrid({
				url: 'content_list.do',
				nowrap: true,
				striped: true,
				border: false,
				fit: true,
				rownumbers:true,
				queryParams: getGueryParams(),
				columns: [[
					{field:'id',checkbox:true},
					{field:'f_cc_id',title:'内容ID',align:'center',width:50},
					{field:'f_cc_name',title:'内容名称',align:'center',width:150},
					{field:'f_cc_duration',title:'部位',align:'center',width:100},
					{field:'f_cc_mediacode',title:'性别',align:'center',width:100},
					{field:'f_cc_obligate1',title:'难度',align:'center',width:100},
                    {field:'f_cc_obligate2',title:'目标',align:'center',width:100},
					//{field:'f_cc_companyname',title:'企业名称',align:'center',width:150},
					{field:'f_cc_type',title:'内容类型',align:'center',width:60,
						formatter:function(value,row,index) {
							var status = "未知";
							if(value==1){
								status="电视剧";
							}else if(value==2){
								status="电影";
							}else if(value==3){
								status="直播";
							} else if(value==4){
								status="图文";
							} else if(value==5){
								status="链接";
							} else if(value==7){
								status="转码视频";
							} else if(value==20){
								status="组织模版";
							} else if(value==100){
								status="业务账号";
							} else if(value==110){
								status="其他";
							}else if(value==50){
								status="参赛人员";
							}else if(value==10){
								status="广告";
							}
							return status;
						}
					},
					{field:'f_cc_isfree',title:'收费状况',align:'center',width:60,
						formatter:function(value,row,index) {
							var status = "收费";
							if(value==0){
								status="收费";
							} else if(value==1){
								status="免费";
							}
							return status;
						}
					},
					{field:'f_cc_status',title:'状态',align:'center',width:80,
						formatter:function(value,row,index) {
							var status = "未知";
							if(value==1){
								status="上线";
							} else if(value==2 || value == 16){
								status="待上线";
							} else if(value==4){
								status="审核未通过";
							} else if(value==5){
								status="待转码";
							} else if(value==6){
								status="正在转码";
							} else if(value==7){
								status="转码失败";
							} else if(value==8){
								status="等待资源";
							} else if(value==9){
								status="资源缺失";
							}else if(value==10){
								status="资源格式/容量不正确";
							}else if(value==11){
								status="待处理";
							}else if(value==12){
								status="不通过";
							}
							return status;
						}
					},
					{field:'f_cc_end',title:'完结状态',align:'center',width:60,
						formatter:function(value,row,index) {
							var end = "";
							if(value==1){
								end="完结";
							} else if(value==0){
								end="未完结";
							}
							return end;
						}
					},
					{field:'f_cc_seriescount',title:'总集数',align:'center',width:45},
					{field:'f_cc_onlinedate',title:'上线时间',align:'center',width:150,
						formatter:function(value,row,index) {
							var str = "";
							if(value!=null)
								str = value.substring(0,19);
							return str;
						}
					},
					{field:'f_cc_offlinedate',title:'下线时间',align:'center',width:150,
						formatter:function(value,row,index) {
							var str = "";
							if(value!=null)
								str = value.substring(0,19);
							return str;
						}
					},
					{field:'f_cc_udate',title:'修改时间',align:'center',width:150},
					{field:'_parentId',title:'操作',align:'center',width:450,
						formatter:function(value,row,index){
							str ="";
							str= '<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="onClickBtnDelete(\''+row.f_cc_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-remove l-btn-icon-left">删除</span></span></a>';
							str+= '<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="edit(\''+row.f_cc_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-edit l-btn-icon-left">修改</span></span></a>';
							str+= '<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="show(\''+row.f_cc_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-search l-btn-icon-left">详情</span></span></a>';
							if(row.f_cc_type==1)
								str+='<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="series(\''+row.f_cc_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-edit l-btn-icon-left">剧集管理</span></span></a>';
							<limits:uiAuth url="review_content.do">
							if(row.f_cc_status==2 || row.f_cc_status==4 || row.f_cc_status==7 || row.f_cc_status == 16) {
								str+='<a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="review(\''+row.f_cc_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-ok l-btn-icon-left">审核</span></span></a>';
							}
							</limits:uiAuth>
							return str;
						}
					}
				]],
				singleSelect:false,
				pagination:true,
				pageList:[10,20,30,40,50,500,1000],
				pageSize:10,
				toolbar: '#toolbar',

				onExpandRow: function(index,row){

				},
				onSelect: function(rowIndex,rowData) {

				},
				onUnselect: function(rowIndex,rowData) {

				},
				onCheckAll: function(rowIndex,rowData) {

				},
				onUncheckAll: function(rowIndex,rowData) {

				},
				onLoadSuccess: function(data) {
					if(data.total==-1) {
						$.messager.defaults={ok:"确定",cancel:"取消"};
						$.messager.confirm('提示', '用户尚未登录,请登录', function(r){
							if (r){
								window.parent.location.href='/login.do';
								return false;
							}});
					}
				}
			});
		}

		function getGueryParams(){
			return {
				f_cc_actors:$("#f_cc_actors").val(),
				f_cc_programatype:"<%=f_cc_programatype%>",
				f_cc_name:$("#f_cc_name").val(),
				f_cc_status:$("#f_cc_status").val(),
				f_cc_type:$("#f_cc_type").val(),
				f_cc_companyid:$("#f_cc_companyid").val(),
				f_cc_mediacode:$("#f_cc_mediacode").val(),
				f_cc_duration:$("#f_cc_duration").val(),
				f_cc_obligate1:$("#f_cc_obligate1").val(),
				f_cc_obligate2:$("#f_cc_obligate2").val()
			};
		}

		$(function(){
			$.ajax({
				url:"../pms/org_list.do",
				success:function(data) {
					data = JSON.parse(data);
					var str = "";
					$('#f_cc_companyid_select').show();
					for(var i=0;i<data.length;i++) {
						str+='<option value="'+data[i].id+'">'+data[i].name+'</option>';
					}
					$("#f_cc_companyid_select").append(str);
					$("#orgSpan").append($("#f_cc_companyid_select").clone(true));
					$('#f_cc_companyid_select').hide();
				}
			});
			new EasyuiDatagrid();
			gotoSearch = function(){
				$("#easyui-datagrid").datagrid('reload',getGueryParams());
			};

			onClickBtnDelete = function(id){
				$.messager.confirm('确定删除内容','确定删除内容么?',function(r){
					if(r){
						app_ajax('delete_content.do?f_cc_id='+id,
								'',
								function(msg){
									if(msg.success) {
										alert("删除成功!");
										if (checkAjaxRequestValidity(msg)) {
											gotoSearch($('#easyui-treegrid'));
										}
									} else {
										alert("删除异常，请联系管理员");
										if($.isFunction(window.showMessager)){
											window.showMessager(msg.resultTitle,msg.result);
										}
									}
								}
						);
					}
				});
			};

			$("#chooseOption1").on("change", function(){
				if($(this).val() == 1){
					$("#chooseOption2").show();
				} else {
					$("#chooseOption2").hide();
				}
			});


		});

		function SubgridTabOnSelect(title,index){
			setTimeout(function(){
				$("#easyui-datagrid").datagrid('fixDetailRowHeight',index);
			},300);
			setTimeout(function(){
				$("#easyui-datagrid").datagrid('fixDetailRowHeight',index);
			},3000);
		}

		function load(){
			$(".datagrid-row-expander datagrid-row-expand").attr("display","none");
		}

		function _resert(){
			$("#f_cc_name").val("");
			$("#f_cc_status").val("");
		}

		function resert(){
			$("#f_cc_company_name").val("");
			$("#f_cc_companyid").val("");
		}

		function onpress(){
			var event=arguments.callee.caller.arguments[0]||window.event;//消除浏览器差异
			if (event.keyCode == 13){
				gotoSearch($('#easyui-treegrid'));
			}
		}

		function edit(id){
			openDialog($("#dlg"),'content_hud_update.jsp?f_cc_id='+id);
		}

		function show(id){
			openDialog($('#dlg'),'content_hud_info.jsp?f_cc_id='+id);
		}

		function add(){
			openDialog($('#dlg'),'content_hud_add.jsp?f_cc_programatype=<%=f_cc_programatype%>');
		}

		function series(id) {
			openDialog($('#seriesdlg'),'series_list.jsp?f_cc_id='+id);
		}

		function review(id) {
			openDialog($('#dlg'),'content_review.jsp?f_cc_id='+id);
		}

		function bind(id) {
			openDialog($('#dlg'),'content_bind.jsp?f_cc_id='+id+'&f_cc_programatype=<%=f_cc_programatype%>');
		}

		function bindOrg() {
			openDialog($('#org_list'),'../industry/behavior_control/org_update.jsp?idField=f_cc_companyid&nameField=f_cc_company_name&batchIdField=f_cc_companyid_select');
		}

		function batchReview() {
			var rows = $("#easyui-datagrid").datagrid('getSelections');
			var ids = '';
			if(rows.length <= 0) {
				alert("请至少选择一条记录!");
			} else {
				for(var i=0;i<rows.length;i++) {
					if(rows[i].f_cc_status == 2 || rows[i].f_cc_status == 4/* || rows[i].f_cc_status == 7 */)
						ids += rows[i].f_cc_id + ',';
				}
				ids = ids.substring(0, ids.length - 1);
				if(ids.length <= 0) {
					alert("请选择至少一条未上线的内容");
				} else {
					$.ajax({
						url:"batch_review_content.do",
						dataType : 'json',
						data : {ids : ids},
						type : 'get',
						success:function(data) {
							alert(data.result);
							gotoSearch($('#easyui-treegrid'));
						}
					});

				}
			}
		}

		function batchUnReview() {
			var rows = $("#easyui-datagrid").datagrid('getSelections');
			var ids = '';
			if(rows.length <= 0) {
				alert("请至少选择一条记录!");
			} else {
				if(confirm("确认是否下线这些记录？")){
					for(var i=0;i<rows.length;i++) {
						ids += rows[i].f_cc_id + ',';
					}
					ids = ids.substring(0, ids.length - 1);
					$.ajax({
						url:"batch_unreview_content.do",
						dataType : 'json',
						data : {ids : ids},
						type : 'get',
						success:function(data) {
							alert(data.result);
							gotoSearch($('#easyui-treegrid'));
						}
					});

				}
			}
		}

		function batchDelete() {
			var rows = $("#easyui-datagrid").datagrid('getSelections');
			var ids = '';
			if(rows.length <= 0) {
				alert("请至少选择一条记录!");
			} else {
				if(confirm("确认是否删除这些记录？")){
					for(var i=0;i<rows.length;i++) {
						ids += rows[i].f_cc_id + ',';
					}
					ids = ids.substring(0, ids.length - 1);
					$.ajax({
						url:"batch_delete_content.do",
						dataType : 'json',
						data : {ids : ids},
						type : 'get',
						success:function(data) {
							alert(data.result);
							gotoSearch($('#easyui-treegrid'));
						}
					});
				}
			}
		}
		function contentSelectAdvertisement(id){
			openDialog($('#dlg'),'content_advertisement.jsp?f_cc_id='+id+"&f_ccadver_type=2");
		}

		function batch_sp_content() {
			openDialog($('#batch_page'),'stream.jsp');
		}
	</script>
</head>
<body onload="load();" style="width: 100%;">
<input type="hidden" id="sessionId" value="${pageContext.session.id}" />
<table id="easyui-datagrid" title="内容列表"></table>
<div id="toolbar" class="easyui_datagrid_toolbar" style="">
	<div class="easyuiSearch">
		<form onsubmit="return false;" method="post">
			<table cellspacing="0" cellpadding="0" width="90%">
				<tr>
					<td align="left" width="7%">计划名称：</td>
					<td align="left" width="15%"><input name="f_cc_name" id="f_cc_name" style="width: 150px;" onkeydown="onpress();" /></td>
					<td align="left" width="7%">计划状态：</td>
					<td align="left" width="30%">
						<select id="f_cc_status" name="f_cc_status">
							<option value="0">请选择</option>
							<option value="1">上线</option>
							<option value="2">待上线</option>
						</select>
					</td>
					<td id="more_condition_three" align="left" width="20%">
						<a href="javascript:void(0);" class="easyui-linkbutton"
						   data-options="iconCls:'icon-add', plain:true" onclick="add()">增加内容</a>
					</td>
				</tr>
				<tr id="more_condition" style="height:26px;display: none">
					<td align="left" width="5%">性&nbsp;&nbsp;别:</td>
					<td align="left" width="20%">
						<select id="f_cc_mediacode" name="f_cc_mediacode">
							<option value="">请选择</option>
							<option value="男">男</option>
							<option value="女">女</option>
						</select>
					</td>
					<td align="left" width="5%">部&nbsp;&nbsp;位:</td>
					<td align="left" width="20%">
						<select id="f_cc_duration" name="f_cc_duration">
							<option value="">--请选择--</option>
							<option value="全身">全身</option>
							<option value="腿部">腿部</option>
							<option value="胸部">胸部</option>
							<option value="背部">背部</option>
							<option value="手臂">手臂</option>
							<option value="臀部">臀部</option>
							<option value="腹部">腹部</option>
						</select>
					</td>
					<td align="left" width="15%">
						<limits:uiAuth url="content_list.do">
							<a href="javascript:void(0);" class="easyui-linkbutton"
							   data-options="iconCls:'icon-search', plain:true"
							   onclick="gotoSearch($('#easyui-datagrid'))">查询</a>
						</limits:uiAuth>
					</td>
					<td align="left" width="35%">
						<limits:uiAuth url="batch_review_content.do">
							<a href="javascript:void(0);" class="easyui-linkbutton"
							   data-options="iconCls:'icon-ok', plain:true"
							   onclick="batchReview()">批量上线</a>
						</limits:uiAuth>
						<limits:uiAuth url="batch_unreview_content.do">
							<a href="javascript:void(0);" class="easyui-linkbutton"
							   data-options="iconCls:'icon-cancel', plain:true"
							   onclick="batchUnReview()">批量下线</a>
						</limits:uiAuth>
						<limits:uiAuth url="batch_delete_content.do">
							<a href="javascript:void(0);" class="easyui-linkbutton"
							   data-options="iconCls:'icon-no', plain:true"
							   onclick="batchDelete()">批量删除</a>
						</limits:uiAuth>
					</td>
				</tr>

				<tr id="more_condition_one" style="height:26px;display: none">
					<td align="left"  width="5%">难&nbsp;&nbsp;度:</td>
					<td align="left" width="20%">
						<select id="f_cc_obligate1" name="f_cc_obligate1">
							<option value="">--请选择--</option>
							<option value="基础">基础</option>
							<option value="初级">初级</option>
							<option value="中级">中级</option>
							<option value="高级">高级</option>
						</select>
					</td>
					<td align="left" width="5%">目&nbsp;&nbsp;的:</td>
					<td align="left" width="20%">
						<select id="f_cc_obligate2" name="f_cc_obligate2">
							<option value="">--请选择--</option>
							<option value="燃脂">燃脂</option>
							<option value="增肌">增肌</option>
							<option value="塑形">塑形</option>
						</select>
					</td>
				</tr>
			</table>
		</form>
	</div>
	<div style="margin-bottom: 5px">
		<!-- <a href="javascript:void(0)" class="easyui-linkbutton" onclick="delete();" iconCls="icon-cut" plain="true">删除</a>  -->
	</div>
</div>
<div id="dlg" class="easyui-dialog"
	 style="width: 950px; height: 600px; padding-top: 0px;"
	 data-options="title:'内容管理', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
	<iframe scrolling="auto" frameborder="0"
			style="width: 100%; height: 99%;"></iframe>
</div>
<div id="seriesdlg" class="easyui-dialog"
	 style="width: 1000px; height: 600px; padding-top: 0px;"
	 data-options="title:'剧集管理', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
	<iframe scrolling="auto" frameborder="0"
			style="width: 100%; height: 99%;"></iframe>
</div>
<div id="org_list" class="easyui-dialog"
	 style="width: 800px; height: 500px; padding-top: 0px;"
	 data-options="title:'客户选择', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
	<iframe scrolling="auto" frameborder="0"
			style="width: 100%; height: 99%;"></iframe>
</div>

<div id="batch_page" class="easyui-dialog"
	 style="width: 800px; height: 500px; padding-top: 0px;"
	 data-options="title:'视频上传', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
	<iframe scrolling="auto" frameborder="0"
			style="width: 100%; height: 99%;"></iframe>
</div>

<div id="win" class="easyui-window" closed="true" modal="true" iconCls="icon-save" style="width:440px; height: 290px; left: 50%px;top: 30%;" title="内容批量导入">
	<div class="easyui-layout" fit="true">
		<div region="north" border="true" style="height: 40px;">
			<a class="easyui-linkbutton" style="line-height: 20px; padding-bottom: 3px;" iconCls="icon-undo" plain="true" href="../static/excel/内容批量导入模版.xlsx">下载模版&nbsp;</a>
		</div>

		<div region="center" border="true">
			<div>
				<p>
					<font size="6" style="font-weight: bold;color: gray;">批量导入说明:</font><br/>
					&nbsp;&nbsp;1. 选择组织(必须):<span id="orgSpan"></span><br/>
					&nbsp;&nbsp;2. 导入选项:&nbsp;&nbsp;&nbsp;<select id="chooseOption1" name="chooseOption1">
					<option value="0">默认</option>
					<option value="1">帐号导入(去重)</option>
				</select>
					<select id="chooseOption2" name="chooseOption2" style="display: none;">
						<option value="1">电视剧</option>
						<option value="2">电影</option>
						<option value="3">直播</option>
						<option value="4">图文</option>
						<option value="5">链接</option>
						<option value="7">转码视频</option>
						<option value="20">组织模板</option>
						<option value="100" selected="selected">业务账号</option>
						<option value="110">其他</option>
						<option value="10">广告</option>
					</select><br/>
					&nbsp;&nbsp;3. 内容类型 1:电视剧, 2:电影, 3:直播, 4:图文, 5:链接, 7:转码视频, 100:业务账号, 110:其他,10:广告<br/>
					&nbsp;&nbsp;4. 是否完结 未完结:0, 完结:1 <br/>
					&nbsp;&nbsp;5. 所有内容都收费<br/>
					&nbsp;&nbsp;6. 上线时间为当前时间<br/>
					&nbsp;&nbsp;7. 下线时间2099-12-31 23:59:59<br/>
				</p>
			</div>
		</div>

		<div region="south" border="false" style="text-align:left;height:40px;padding: 3px">
			<input id="uploadFile2"  type="file" name="file"/>
		</div>

	</div>
</div>


<script type="text/javascript">
	$(function(){
		$('#win').window({
			onBeforeClose:function(){
				//window.location.reload();	
			}
		});
		initFileUpload("#uploadFile2", {});
	});

	function batch_add(){
		$('#win').window('open');
	}


	function initFileUpload(inputId, params){
		var action = 'insert_batch_content.do;jsessionid='+$("#sessionId").val();
		$(inputId).uploadify({
			'swf'           :'../swf/uploadify.swf',
			'uploader'      :action,
			'formData'      :params,
			'fileObjName'   :'uploadify',
			'cancelImg' 	:"../imgs/uploadify-cancel.png",
			'queueId'		:"fileQueue",
			'fileTypeDesc'  :"Excel File",
			'fileTypeExts'	:"*.xls; *.xlsx",//限制文件类型
			'auto'			:true,//是否自动上传
			'multi'			:false,//是否允许多文件上传
			'buttonText'	:"导入文档",
			'method'		:"POST",
			'successTimeout':1200,
			'onInit'        : function(){
			},
			'onUploadStart' : function(file){
				var orgId = $("#win #f_cc_companyid_select").val();
				if(!(orgId && orgId > 0)){
					$(inputId).uploadify('cancel');
					alert("请选择组织！");
				}else{
					$(inputId).uploadify('settings','formData', {"f_cc_companyid" : orgId,"f_cc_programatype" : "<%=f_cc_programatype%>", "chooseOption1" : $("#win #chooseOption1").val(), "chooseOption2" : $("#win #chooseOption2").val()});
					jQuery.messager.alert('批量导入','批量导入开始, 操作结果请稍后.');
				}
			},
			'onUploadSuccess' : function(file,data,response) {
				if(data != null && data != undefined && data != ''){
					jQuery.messager.alert('批量导入',data);
				}
			},
			'onUploadError' : function(file, errorCode, errorMsg, errorString) {
				if(errorMsg == '302'){
					jQuery.messager.alert('批量导入','批量导入失败，请检查登录状态或者无此权限!');
				}
			}
		});
	}
	function exportExcel(){
		$.messager.confirm('导出','确定导出内容么?',function(r){
			if(r){
				var pager = $("#easyui-datagrid").datagrid("getPager").data("pagination").options;;
				var page=pager.pageNumber;
				var rows=pager.pageSize;
				var f_cc_name=$("#f_cc_name").val();
				var f_cc_status=$("#f_cc_status").val();
				var f_cc_type=$("#f_cc_type").val();
				var f_cc_companyid=$("#f_cc_companyid").val();
				var f_cc_programatype="<%=f_cc_programatype%>";
				var f_cc_actors=$("#f_cc_actors").val();
				var url="content_excel_list.do?f_cc_name="+f_cc_name+"&f_cc_status="+f_cc_status+"&f_cc_type="+f_cc_type+"&f_cc_companyid="+f_cc_companyid+"&page="+page+"&rows="+rows+"&f_cc_programatype="+f_cc_programatype+"&f_cc_actors="+f_cc_actors;
				window.open(url);
			}
		});
	}
</script>
</body>
</html>